﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace Util
{
    public class Report
    {
        List<Equipamento> Equipamentos
        {
            get;
            set;
        }
        public Document Documento
        {
            get;
            set;
        }
        public Report()
        {
        }

        public MemoryStream CriarRelatorio(List<Equipamento> equipamentos)
        {
            MemoryStream PDFData = new MemoryStream();
            Document document = new Document(PageSize.LETTER, 50, 50, 80, 50);
            PdfWriter PDFWriter = PdfWriter.GetInstance(document, PDFData);
            PDFWriter.ViewerPreferences = PdfWriter.PageModeUseOutlines;


            document.Open();
            
            foreach (Equipamento e in equipamentos)
            {
                document.NewPage();
                
                Image logo = Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory+"/images/logoferro.png");
                logo.ScalePercent(60, 60);
                document.Add(logo);
                
                Paragraph tituloPagina = new Paragraph(e.Nome);
                Paragraph subtitulo = new Paragraph(e.Tipo.ToString());
                Paragraph descricaoLabel = new Paragraph("Descrição:");
                Paragraph descricao = new Paragraph(e.Descrição);
                

                tituloPagina.Font.SetFamily("Helvetica");
                tituloPagina.Font.Size = 18;

                subtitulo.Font.SetFamily("Helvetica");
                subtitulo.Font.Size = 16;

                descricaoLabel.Font.SetStyle(Font.BOLD);

                document.Add(tituloPagina);
                document.Add(subtitulo);
                document.Add(descricaoLabel);
                document.Add(descricao);
            }
            
           
            document.Close();

            return PDFData;
        }

        public void AddOutline(PdfWriter writer, string Title, float Position)
        {
            PdfDestination destination = new PdfDestination(PdfDestination.FITH, Position);
            PdfOutline outline = new PdfOutline(writer.DirectContent.RootOutline, destination, Title);
            writer.DirectContent.AddOutline(outline, "Name = " + Title);
        }

    }
}
